{% extends "layout.html" %}

{% block head %}
<script type="text/javascript" src="{{ url_for('static', filename='vendors/tinymce/tinymce.min.js') }}"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
<script type="text/javascript">
	tinymce.init({ 
		selector: "textarea",
		plugins : "advlist autolink link image lists charmap print preview textcolor emoticons directionality fullscreen table wordcount code",
		toolbar : "undo redo | styleselect | alignleft aligncenter alignright alignjustify ltr rtl | outdent indent blockquote removeformat bullist numlist | forecolor backcolor underline strikethrough italic bold | insertdatetime code preview emoticons table link image",
	});
	function checkTinymce() {
		var body = tinyMCE.activeEditor.getBody();
 		var content = tinyMCE.trim(body.innerText || body.textContent);
		if ((content.length == 0)) {
			window.alert("{{ _('Please fill content area.') }}");
			return false;
		} else {
			return true;
		}
	}
</script>
{% if mode == "edit" %}
	<title>{{ _(config["WEBSITE_NAME"]) }} - {{ _("Edit Post") }}</title>
{% elif mode == "add" %}
	<title>{{ _(config["WEBSITE_NAME"]) }} - {{ _("Add Post") }}</title>
{% endif %}
<meta name="robots" content="noindex,nofollow">
{% endblock %}

{% block body %}
<div class="container-fluid text-center">
	{% if get_flashed_messages() %}
		<div class="alert alert-warning">
			<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
  			<strong>{{ _("Warning!") }}</strong> {{ _("Post address is not avaliable.") }}
		</div>
	{% endif %}
	<form method="POST" onsubmit="return checkTinymce();">
		{% if mode == "edit" %}
			<input class="form-control" placeholder="{{ _('Post Header') }}" type="text" autofocus name="post-header" id="post-header" value="{{ query.address }}" required><br>
			<textarea style="display: block !important; height: 400px;" placeholder="{{ _('Page Content') }}" rows="10" cols="100" name="content">
				{{ query.content }}
			</textarea><br>
			<input type="hidden" name="id" value="{{ query.Id }}">
	 		<input class="btn btn-md btn-default" formaction="{{ url_for('wiki.edit_post', post=query.url) }}" type="submit" value="{{ _('Submit') }}">
		{% elif mode == "add" %}
			<input class="form-control" placeholder="{{ _('Post Header') }}" type="text" autofocus id="post-header" name="post-header" required><br>
			<textarea style="display: block !important; height: 400px;" placeholder="{{ _('Page Content') }}" rows="10" cols="100" name="content"></textarea><br>
	 		<input class="btn btn-md btn-default" formaction="{{ url_for('wiki.add_post') }}" type="submit" value="{{ _('Submit') }}">
		{% endif %}
		<input type="submit" class="btn btn-md btn-default" formaction="{{ url_for('wiki.perview') }}" formtarget="_blank" value="{{ _('Perview') }}">
	</form>
</div>
{% endblock %}